package trism.game.model.common.stat.levels {
	import com.samoiloff.util.data.ArrItem;

	import flash.utils.ByteArray;
	/**
	 * @author Samoiloff  http://samoiloff.com/
	 */
	public class LevelsItem extends ArrItem {
		
		
		[Embed(source="../../../../../../../lib/levels.xml", mimeType="application/octet-stream")]
		private const _defaultXML : Class;
		
		public function LevelsItem() {
			
		}
		
		public function update(xml:XML):void {
			for each(var level_xml:XML in xml.level) {
				var levelItem:LevelItem = new LevelItem(level_xml);
				_arr.push(levelItem);
			}
		}
		
		public function getEmbedLevelsXML() : XML {
			var ba:ByteArray = new _defaultXML() as ByteArray;
			var str:String = ba.readUTFBytes(ba.length);
			while (str.charAt(0) != "<") { 
				str = str.substr(1); 
			}
			return new XML(str);
		}
		
		public function getItemAt(i:int):LevelItem {
			return _arr[i] as LevelItem;
		}
		
		public function getItemIndex(levelItem:LevelItem):int {
			for (var i:int = 0; i<length; i++) {
				if (getItemAt(i) == levelItem) {
					return i;
				}
			}
			return -1;
		}
		
		
	}
}
